package com.zzh.web;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zzh.model.EbProduct;
import com.zzh.model.EbProductCategory;
import com.zzh.service.EbProductCategoryService;
import com.zzh.service.EbProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/index")
public class IndexController{
    @Autowired
    private EbProductService ebProductService;
    @Autowired
    private EbProductCategoryService ebProductCategoryService;


    @RequestMapping("/front")
    public String index(@RequestParam(defaultValue = "1") int psize,
                        @RequestParam(defaultValue = "8") int pageSize,
                        Model model, HttpServletRequest request){
        System.out.println("访问前台首页");
        Page<EbProduct> productPage = ebProductService.list(psize,pageSize);

        Map<String, List<EbProductCategory>> cateMap = ebProductCategoryService.selectBigAndSmallCate();
        model.addAttribute("productPage",productPage);
        //model.addAttribute("cateMap",cateMap);
        request.getSession().setAttribute("cateMap",cateMap);
        return  "index";
    }
}


